/*
 * Copyright (c) 2010. raoqn
 */

package com.yfeng.goodjuhome.model;

import com.yfeng.common.dao.IDao;
import com.yfeng.exception.ModelException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * www.goodjuhome.com
 * Created by IntelliJ IDEA.
 * User: rqn
 * Date: 2010-8-14
 * Time: 16:55:56
 */
@Component
public class Product {
     private final Log log = LogFactory.getLog(this.getClass());

    @Autowired
    public IDao baseDao;

     private String id,uid,big_type,mid_type,name,make_company,supplier,price,norm,brand,design_key_point,setup_key_point,project_type,exec_norm,note,createtime,upload_image;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getBig_type() {
        return big_type;
    }

    public void setBig_type(String big_type) {
        this.big_type = big_type;
    }

    public String getMid_type() {
        return mid_type;
    }

    public void setMid_type(String mid_type) {
        this.mid_type = mid_type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMake_company() {
        return make_company;
    }

    public void setMake_company(String make_company) {
        this.make_company = make_company;
    }

    public String getSupplier() {
        return supplier;
    }

    public void setSupplier(String supplier) {
        this.supplier = supplier;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getNorm() {
        return norm;
    }

    public void setNorm(String norm) {
        this.norm = norm;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getDesign_key_point() {
        return design_key_point;
    }

    public void setDesign_key_point(String design_key_point) {
        this.design_key_point = design_key_point;
    }

    public String getSetup_key_point() {
        return setup_key_point;
    }

    public void setSetup_key_point(String setup_key_point) {
        this.setup_key_point = setup_key_point;
    }

    public String getProject_type() {
        return project_type;
    }

    public void setProject_type(String project_type) {
        this.project_type = project_type;
    }

    public String getExec_norm() {
        return exec_norm;
    }

    public void setExec_norm(String exec_norm) {
        this.exec_norm = exec_norm;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public String getUpload_image() {
        return upload_image;
    }

    public void setUpload_image(String upload_image) {
        this.upload_image = upload_image;
    }

    public ProductTypeModel  getProductMidType()   throws ModelException
    {
         try
         {
           List result =  baseDao.query("select * from mb_product_mid where id='"+this.getMid_type()+"'");
             if(result.size()>0)
             {
                 Map map = (Map) result.get(0);

                 ProductTypeModel model = new ProductTypeModel();
                 model.setId(map.get("id").toString());
                 model.setName(map.get("name").toString());
                 model.setCreateTime(map.get("createtime").toString());
                 return model;
             }
             else
                 return null;
         }
        catch (Exception e)
        {
            log.error(e.getMessage(),e);
            throw new ModelException(e.getMessage(),e);
        }
    }


    /**
     *
     * @return
     * @throws ModelException
     */
    public ProductTypeModel  getProductBigType()   throws ModelException
    {
         try
         {
           List result =  baseDao.query("select * from mb_product_big where id='"+this.getBig_type()+"'");
             if(result.size()>0)
             {
                 Map map = (Map) result.get(0);

                 ProductTypeModel model = new ProductTypeModel();
                 model.setId(map.get("id").toString());
                 model.setName(map.get("name").toString());
                 model.setCreateTime(map.get("createtime").toString());
                 return model;
             }
             else
                 return null;
         }
        catch (Exception e)
        {
            log.error(e.getMessage(),e);
            throw new ModelException(e.getMessage(),e);
        }
    }

    @Override
    public String toString() {
        return "Product{" +
                "baseDao=" + baseDao +
                ", id='" + id + '\'' +
                ", uid='" + uid + '\'' +
                ", big_type='" + big_type + '\'' +
                ", mid_type='" + mid_type + '\'' +
                ", name='" + name + '\'' +
                ", make_company='" + make_company + '\'' +
                ", supplier='" + supplier + '\'' +
                ", price='" + price + '\'' +
                ", norm='" + norm + '\'' +
                ", brand='" + brand + '\'' +
                ", design_key_point='" + design_key_point + '\'' +
                ", setup_key_point='" + setup_key_point + '\'' +
                ", project_type='" + project_type + '\'' +
                ", exec_norm='" + exec_norm + '\'' +
                ", note='" + note + '\'' +
                ", createtime='" + createtime + '\'' +
                ", upload_image='" + upload_image + '\'' +
                '}';
    }
}
